

#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    int maxSubArray1(vector<int>& nums)
    {
        int res = nums[0];
        int n = nums.size();
        vector<int> dp(n);

        dp[0] = nums[0];
        for (int i = 1; i < n; ++i)
        {
            dp[i] = max(dp[i - 1] + nums[i], nums[i]);
            res = max(res, dp[i]);
        }

        return res;
    }

    int maxSubArray2(vector<int>& nums)
    {
        int res = nums[0];
        int n = nums.size();

        for (int i = 1, prev = nums[0], fi = 0; i < n; ++i)
        {
            fi = max(prev + nums[i], nums[i]);
            res = max(res, fi);
            prev = fi;
        }

        return res;
    }

    int maxSubArray3(vector<int>& nums)
    {
        int res = nums[0];
        int n = nums.size();

        for (int i = 1, prev = nums[0]; i < n; ++i)
        {
            prev = max(prev + nums[i], nums[i]);
            res = max(res, prev);
        }

        return res;
    }

    int maxSubArray4(vector<int>& nums)
    {
        int prev = 0, res = nums[0];

        for (const auto& e : nums)
        {
            prev = max(prev + e, e);
            res = max(res, prev);
        }

        return res;
    }

    int maxSubArray5(vector<int>& nums)
    {
        int res = INT_MIN, sum = 0;

        for (const auto& e : nums)
        {
            sum += e;
            res = max(res, sum);

            if (sum < 0)
                sum = 0;
        }

        return res;
    }

    vector<int> productExceptSelf1(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> ans(n);
        vector<int> prefix(n), suffix(n);

        prefix[0] = nums[0], suffix[n - 1] = nums[n - 1];
        for (int i = 1; i < n; ++i)
        {
            prefix[i] = prefix[i - 1] * nums[i];
        }
        for (int i = n - 2; i >= 0; --i)
        {
            suffix[i] = suffix[i + 1] * nums[i];
        }

        ans[0] = suffix[1], ans[n - 1] = prefix[n - 2];
        for (int i = 1; i < n - 1; ++i)
        {
            ans[i] = prefix[i - 1] * suffix[i + 1];
        }

        return ans;
    }

    vector<int> productExceptSelf2(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> ans(n);
        vector<int> prefix(n), suffix(n);

        prefix[0] = suffix[n - 1] = 1;
        for (int i = 1; i < n; ++i)
        {
            prefix[i] = prefix[i - 1] * nums[i - 1];
        }
        for (int i = n - 2; i >= 0; --i)
        {
            suffix[i] = suffix[i + 1] * nums[i + 1];
        }

        for (int i = 0; i < n; ++i)
        {
            ans[i] = prefix[i] * suffix[i];
        }

        return ans;
    }

    vector<int> productExceptSelf3(vector<int>& nums)
    {
        int n = nums.size(), suffix = 1;
        vector<int> prefix(n);

        prefix[0] = 1;
        for (int i = 1; i < n; ++i)
        {
            prefix[i] = prefix[i - 1] * nums[i - 1];
        }
        for (int i = n - 2; i >= 0; --i)
        {
            suffix = suffix * nums[i + 1];
            prefix[i] = prefix[i] * suffix;
        }

        return prefix;
    }
};

int main()
{


	return 0;
}